﻿using CommonCater;
using Lufei_CaterBLL;
using Lufei_CaterModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lufei_CaterUI
{
    public partial class FrmChangeDesk : Form
    {
        public FrmChangeDesk()
        {
            InitializeComponent();
        }



        DeskInfo desk =null;
        public void SetValue(object sender,EventArgs e)
        {
            UpdateMemmberInfo<DeskInfo> memmberInfo =e as UpdateMemmberInfo<DeskInfo>;
            if (memmberInfo!=null)
            {
                desk = memmberInfo.obj;
                DeskName.Text = desk.DeskName;
                DeskRemark.Text = desk.DeskRemark;
                DeskRegion.Text = desk.DeskRegion;
                comDeskState.SelectedIndex= desk.DeskState;
                DeskId=desk.DeskId;
            }

        }


        /// <summary>
        /// 获取所有房间类型
        /// </summary>
        private void LoadRoomType()
        {
            RoomInfoBLL roomInfoBLL = new RoomInfoBLL();
            List<RoomInfo> rooms = roomInfoBLL.GetRoomsByDelFlag();
            txtcmb.ValueMember = "RoomId";
            txtcmb.DisplayMember = "RoomName";
            txtcmb.DataSource = rooms;
            txtcmb.SelectedValue = desk.RoomId;
        }
        
        private void FrmChangeDesk_Load(object sender, EventArgs e)
        {
            LoadRoomType();
        }


        public int DeskId { get; set; }

        private void btnOk_Click(object sender, EventArgs e)
        {
            DeskInfoBLL bll = new DeskInfoBLL();
            DeskInfo desk1 = new DeskInfo();
            desk1.DeskId = DeskId;
            desk1.RoomId =Convert.ToInt32(txtcmb.SelectedValue);
            desk1.DeskName = DeskName.Text;
            desk1.DeskRemark= DeskRemark.Text;
            desk1.DeskRegion=DeskRegion.Text;
            desk1.DeskState = comDeskState.SelectedIndex;
             bool isUpdate=  bll.UpdateDeskInfo(desk1);
            if (isUpdate)
            {
                MessageBox.Show("修改桌子成功");
                log<FrmChangeDesk>.LogDebug("修改桌子成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("修改桌子失败");
                log<FrmChangeDesk>.LogError("修改桌子失败");
                this.Close();
            }
        }
    }
}
